import request from "@/utils/request";
import { downloadNew } from "@/utils/request";
import _ from 'lodash';
import md5 from 'js-md5'
//user
export function getUserList(param) {
  return request({
    url: "/car/admin/upms/user/page",
    method: "post",
    data: param,
    headers: { "Content-Type": "application/json" },
  });
}
export function editUser(param) {
  var data = _.cloneDeep(param);
  data.password = md5(data.password)
  return request({
    url: "/car/admin/upms/user/add",
    method: "post",
    data: data,
    headers: { "Content-Type": "application/json" },
  });
}
export function editUserPassword(id,oldPassword,newPassword) {
  oldPassword = md5(oldPassword)
  newPassword = md5(newPassword)
  return request({
    url: "/car/admin/upms/user/editPassword?id="+id+"&oldPassword="+oldPassword+"&newPassword="+newPassword,
    method: "post",
    headers: { "Content-Type": "application/json" },
  });
}
export function lockUser(id, flag) {
  return request({
    url: "car/admin/upms/user/lock?userId=" + id + "&locked=" + flag,
    method: "post",
    headers: { "Content-Type": "application/json" },
  });
}
export function updateUserGroup(userId,groupId) {
  return request({
    url: "/car/admin/upms/user/updateGroup?userId="+userId+"&groupId="+groupId,
    method: "post",
    headers: { "Content-Type": "application/json" },
  });
}

//gruop
export function getGroupList(param) {
  return request({
    url: "/car/admin/upms/group/page",
    method: "post",
    data: param,
    headers: { "Content-Type": "application/json" },
  });
}
export function editGroup(param) {
  param.groupPermission = _.toString(param.groupPermission)
  return request({
    url:  "/car/admin/upms/group/add" ,
    method: "post",
    data: param,
    headers: { "Content-Type": "application/json" },
  });
}
export function delGroup(id) {
  return request({
    url: "/car/admin/upms/group/del?id=" + id,
    method: "post",
    headers: { "Content-Type": "application/json" },
  });
}
export function getGroupDetail(id) {
  return request({
    url: "/car/admin/upms/group/detail?id=" + id,
    method: "post",
    headers: { "Content-Type": "application/json" },
  });
}

//Permissions
export function getPermissionsList() {
  return request({
    url: "/car/admin/upms/group/listAllPermissions",
    method: "get",
    headers: { "Content-Type": "application/json" },
  });
}

//partner
export function getPartnerList(param) {
  return request({
    url: "/car/admin/partner/pageData",
    method: "post",
    data: param,
    headers: { "Content-Type": "application/json" },
  });
}
export function getAllPartnerList() {
  return request({
    url: "/car/admin/partner/listData",
    method: "post",
    data: null,
    headers: { "Content-Type": "application/json" },
  });
}
// export function addPartner(param) {
//   var data = _.cloneDeep(param);
//   data.password = md5(data.password)
//   return request({
//     url: "/car/admin/partner/addPartner",
//     method: "post",
//     data: data,
//     headers: { "Content-Type": "application/json" },
//   });
// }
// export function editPartner(param) {
//   var data = _.cloneDeep(param);
//   data.password = md5(data.password)
//   return request({
//     url: "/car/admin/partner/editPartner",
//     method: "post",
//     data: data,
//     headers: { "Content-Type": "application/json" },
//   });
// }
export function updatePartnerStatus(id, flag) {
  return request({
    url: "/car/admin/partner/updatePartnerStatus?id=" + id + "&status=" + flag,
    method: "post",
    headers: { "Content-Type": "application/json" },
  });
}